package com.example.demo.controller;

import com.example.demo.entity.ResponseInfo;
import com.example.demo.entity.UITestCase;
import com.example.demo.entity.request.uiTestCaseReq.UITestCaseAddReq;
import com.example.demo.entity.request.uiTestCaseReq.UITestCaseUpdateReq;
import com.example.demo.service.UITestCaseService;
import com.example.demo.utils.PageInfoNew;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

@RestController
@Validated
@RequestMapping("/UITestCase")
@Api(value = "/UITestCase", tags = "ui测试用例接口")
public class UITestCaseController {

    @Resource
    UITestCaseService uiTestCaseService;

    @PostMapping("/add")
    @ApiOperation(value = "ui测试用例新增接口")
    public ResponseInfo<String> add(@RequestBody UITestCaseAddReq req) {
        req.validate();
        uiTestCaseService.add(req);
        return ResponseInfo.successInfo("");
    }

    @PostMapping("/update")
    @ApiOperation(value = "ui测试用例更新接口")
    public ResponseInfo<String> update(@RequestBody UITestCaseUpdateReq req) {
        req.validate();
        uiTestCaseService.update(req);
        return ResponseInfo.successInfo("");
    }

    @GetMapping("/page")
    @ApiOperation(value = "ui测试用例分页接口")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "pageNum", value = "页数", required = true, dataType = "int"),
            @ApiImplicitParam(name = "pageSize", value = "每页长度", required = true, dataType = "int"),
            @ApiImplicitParam(name = "uiTestCaseSuiteId", value = "ui测试用例类别的id", required = false, dataType = "long"),
            @ApiImplicitParam(name = "name", value = "ui测试用例名称", required = false, dataType = "string"),
            @ApiImplicitParam(name = "projectId", value = "项目id", required = false, dataType = "int")
    })
    public ResponseInfo<PageInfoNew<UITestCase>> page(@RequestParam Integer pageNum,
                                                      @RequestParam Integer pageSize,
                                                      @RequestParam(value = "uiTestCaseSuiteId", required = false) Long uiTestCaseSuiteId,
                                                      @RequestParam(value = "name", required = false) String name,
                                                      @RequestParam(value = "projectId", required = false) Long projectId) {
        return ResponseInfo.successInfo(uiTestCaseService.page(pageNum, pageSize, uiTestCaseSuiteId, name, projectId));
    }

    @PostMapping("/debug")
    @ApiOperation(value = "测试用例debug接口")
    @ApiImplicitParam(name = "id", value = "测试用例id", required = true, dataType = "long")
    public ResponseInfo<String> debug(@RequestParam Long id) {
        uiTestCaseService.debug(id);
        return ResponseInfo.successInfo("");

    }

    @DeleteMapping("/delete/{id}")
    public ResponseInfo<String> delete(@PathVariable(value = "id") Long id) {
        uiTestCaseService.deleteById(id);
        return ResponseInfo.successInfo("");
    }
}
